from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter

import feedparser

register = template.Library()

@stringfilter
def tla_links(value):
    feed_url = settings.TLA_LINK #"http://www.text-link-ads.com/xml_blogger.php?inventory_key=JZQM1VNNTDX78IEBIPO5"
    d = feedparser.parse(feed_url)
    feed_title = d.feed.title
    t = "<h3>%s</h3><p class='about'>" % feed_title
    
    url =''
    summary = ''
    entry_title = ''
    
    for entry in d.entries:
        url = entry.link
        summary = entry.description
        entry_title = entry.title
        t += "<a href='%s'>%s</a><br />" % (url, entry_title)
    
    t += "</p>"
    
    return t

register.filter('tla_links', tla_links)